(ns ver
  (:use util.contrib.with-ns))


(defmacro ver-patch
  ([n1 n2 v]
    `(with-ns '~n1
      (def ~v ~(symbol (str n2) (str v)))))
  ([n1 n2]
    (require n1)
    (require n2)
    `(do
      ~@(for [[n v] (ns-interns (the-ns n2)) :when (not (:private (meta v)))]
        `(ver-patch ~n1 ~n2 ~n)))))

(defn var-patch-vars [n1 n2]
  (require n1)
  (require n2)
  (let [n1-vars (ns-interns (the-ns n1))
        n2-vars (ns-interns (the-ns n2))]
    (doseq [[s n2-var] n2-vars :when (not (:private (meta n2-var)))]
      (when-let [n1-var (get n1-vars s)]
        (alter-var-root n1-var (constantly @n2-var))))))


